const TOKEN_KEY = 'token';
const USER_KEY = 'user_info';

const isLogin = () => {
  return !!localStorage.getItem(TOKEN_KEY);
};

const getToken = () => {
  return localStorage.getItem(TOKEN_KEY);
};

const setToken = (token: string) => {
  localStorage.setItem(TOKEN_KEY, token);
};

const setUserInfo = (userInfo: any) => {
  localStorage.setItem(USER_KEY, JSON.stringify(userInfo));
};

const getUserInfo = () => {
  return JSON.parse(localStorage.getItem(USER_KEY)+'');
};

const clearToken = () => {
  localStorage.removeItem(TOKEN_KEY);
};

export { isLogin, getToken, setToken, clearToken, setUserInfo, getUserInfo };
